package vim.meet.javassist.base;

import javassist.*;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class ClassPoolSearchPathTest {
	
	public static void main(String[] args) {
		//默认加载方式如pool.insertClassPath(new ClassClassPath(this.getClass()));
		ClassPool pool = ClassPool.getDefault();
		//从file加载classpath
		try {
			pool.insertClassPath("/usr/local/javalib");
		} catch (NotFoundException e) {
			e.printStackTrace();
		}
		//从URL中加载
		ClassPath cp = new URLClassPath("www.javassist.org", 80, "/java/", "org.javassist.");
		pool.insertClassPath(cp);
		//从byte[] 中加载
		byte[] b = new byte[8192];
		String name = ClassPoolSearchPathTest.class.getName();
		((ClassPool) cp).insertClassPath(new ByteArrayClassPath(name, b));
		//可以从输入流中加载class
		InputStream ins = null;
		try {
			ins = new FileInputStream("");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		try {
			@SuppressWarnings("unused")
			CtClass cc = ((ClassPool) cp).makeClass(ins);
		} catch (IOException | RuntimeException e) {
			e.printStackTrace();
		}
	}

}
